import $http from "@/core/utils/http";
import {getAdminVersion, setAdminShowLog, setAdminVersion, setServerVersion, setStorage,} from "@/core/utils/storage";

export const API = {
    //文件上传
    adminUploadUrl: '/admin/upload/uploadFile',

    /**
     * 音频
     */
    audioPeopleApproval: "/people_approval.mp3",//发布注册信息审批声音
    audioRequireApproval: "/require_approval.mp3",//发布需求审批声音
    audioApplicationApproval: "/application_approval.mp3",//发布应用审批声音
    // audioRequireApproval: "http://218.27.78.27:81/group1/M00/00/03/CklEiF5FjL6AUcfzAAApoC76aGY138.mp3",//发布需求审批声音
    // audioApplicationApproval: "http://218.27.78.27:81/group1/M00/00/03/CklEiF5FjISAKIC2AAAn8Lm3vKk770.mp3",//发布应用审批声音

    /**
     *
     */
    //企业详情
    companyInfoInsert: "/company/companyInfo/insert",//
    companyInfoResetPassword: "/company/companyInfo/resetPassword",//
    companyInfoDelete: "/company/companyInfo/delete",//
    companyInfoUpdate: "/company/companyInfo/update",//
    companyInfoInfo: "/company/companyInfo/info",//
    companyInfoByUserId: "/company/companyInfo/infoByUserId",//
    companyInfoList: "/company/companyInfo/list",//
    companyInfoPage: "/company/companyInfo/page",//
    validateInfoByUserId: "/company/companyInfo/validateInfoByUserId",// 验证企业信息是否填写完整


    //员工基本情况
    inWorkHumanInfoInsert: "/inWork/humanInfo/insert",//
    inWorkHumanInfoDelete: "/inWork/humanInfo/delete",//
    inWorkHumanInfoUpdate: "/inWork/humanInfo/update",//
    inWorkHumanInfoInfo: "/inWork/humanInfo/info",//
    inWorkHumanInfoList: "/inWork/humanInfo/list",//
    inWorkHumanInfoPage: "/inWork/humanInfo/page",//
    inWorkHumanInfoByMonth: "/inWork/humanInfo/inWorkHumanInfoByMonth",// 根据月份查询
    inWorkHumanStatisticsTableExport: "/inWork/humanInfo/statisticsTable/export",//统计表导出
    inWorkHumanStatisticsTablePage: "/inWork/humanInfo/statisticsTable/page",//统计表分页查询


    //行业类别
    industryTypeInsert: "/industry/type/insert",//
    industryTypeDelete: "/industry/type/delete",//
    industryTypeUpdate: "/industry/type/update",//
    industryTypeInfo: "/industry/type/info",//
    industryTypeList: "/industry/type/list",//
    industryTypePage: "/industry/type/page",//


    //用人单位招聘信息
    recruitCompanyInfo: "/recruitInfo/getCompanyInfo",//
    recruitSubmit: "/recruitInfo/submit",//提交当月的招聘信息
    recruitCheckNowMonthData: "/recruitInfo/checkNowMonthData",//
    recruitInfo: "/recruitInfo/getRecruitInfo",//
    recruitJobInfoS: "/recruitInfo/getRecruitJob",//
    recruitAlJobNames: "/recruitInfo/allJobNames",//查询企业所属全部岗位名称
    recruitTypeJobNames: "/recruitInfo/typeJobNames",//查询企业所属全部岗位名称
    recruitStatisticsTableExport: "/recruitInfo/statisticsTable/export",//统计表导出
    recruitStatisticsTablePage: "/recruitInfo/statisticsTable/page",//统计表分页查询
    recruitInsertOrUpdate: "/recruitInfo/insertOrUpdate",//添加招聘信息
    recruitDelete: "/recruitInfo/delete",//删除招聘信息
    // recruitInsertJob: "/recruitInfo/insertRecruitJob",

    recruitInfoInsert: "/recruitInfo/insert",//
    recruitInfoDelete: "/recruitInfo/delete",//
    recruitInfoUpdate: "/recruitInfo/update",//
    recruitInfoInfo: "/recruitInfo/info",//
    recruitInfoList: "/recruitInfo/list",//
    recruitInfoPage: "/recruitInfo/page",//

    // 动态人力资源信息
    dynamicHumanInfoInsert: "/dynamicHumanInfo/insert",//
    dynamicHumanInfoDelete: "/dynamicHumanInfo/delete",//
    dynamicHumanInfoUpdate: "/dynamicHumanInfo/update",//
    dynamicHumanInfoInfo: "/dynamicHumanInfo/info",//
    dynamicHumanInfoList: "/dynamicHumanInfo/list",//
    dynamicHumanInfoPage: "/dynamicHumanInfo/page",//
    dynamicHumanInfoByMonth: "/dynamicHumanInfo/dynamicHumanInfoByMonth",//根据月份查询
    dynamicHumanInfoStatisticsTableExport: "/dynamicHumanInfo/statisticsTable/export",//用工动态统计表导出
    dynamicHumanInfoStatisticsTablePage: "/dynamicHumanInfo/statisticsTable/page",//用工动态统计表分页查询
    companyUnitTypeStatistical: "/company/companyInfo/companyUnitTypeStatistical",// 企业性质统计图
    companyIndustryTypeStatistical: "/company/companyInfo/companyIndustryTypeStatistical",// 行业比较统计图
    dynamicHumanInfoStatistical: "/dynamicHumanInfo/statisticalChart/dynamicHumanInfoStatistical", // 企业用工动态统计图


    /**
     * System模块API
     */

    //字典
    sysDictPage: "/system/dict/page",//
    sysDictInsert: "/system/dict/insert",//
    sysDictDel: "/system/dict/delete",//
    sysDictUpdate: "/system/dict/update",//


    // * 菜单
    sysMenuInsert: "/system/menu/insert",//
    sysMenuDel: "/system/menu/delete",//
    sysMenuUpdate: "/system/menu/update",//
    sysMenuPage: "/system/menu/page",//
    sysMenuInfo: "/system/menu/info",//
    sysMenuAll: "/system/menu/all",//
    sysMenuSubmit: "/system/menu/submitMenu",//

    // * 资源
    sysResourceInsert: "/system/resource/insert",//
    sysResourceDel: "/system/resource/delete",//
    sysResourceUpdate: "/system/resource/update",//
    sysResourcePage: "/system/resource/page",//
    sysResourceInfo: "/system/resource/info",//
    sysResourceAll: "/system/resource/all",//

    // * 角色
    sysAllRole: "/system/role/allRole",//
    sysRoleAllMenuResource: "/system/role/allMenuResource",//
    sysRoleOne: "/system/role/one",//
    sysRolePage: "/system/role/page",//
    sysRoleInsert: "/system/role/insert",//
    sysRoleMenu: "/system/role/roleMenu",
    sysRoleResource: "/system/role/roleResource",
    sysRoleDel: "/system/role/delete",//
    sysRoleList: "/system/role/list",//
    sysRoleUpdate: "/system/role/update",//

    // * 用户
    tokenLogin: "/system/user/public/tokenLogin",

    sysUserLoginTimeline: "/system/user/loginTimeline",//
    sysUserInfo: "/system/user/info",//
    sysUserPage: "/system/user/page",//
    sysUserInsert: "/system/user/insert",//
    sysUserDel: "/system/user/delete",//
    sysUserUpdate: "/system/user/update",//
    sysUpdatePassword: "/system/user/updatePassword",//
    sysResetPassword: "/system/user/resetPassword",//

    // * 请求日志
    sysRequestLogPage: "/system/requestLongLog/page",//
    sysRequestLogDelete: "/system/requestLongLog/delete",//

    //刷新缓存
    sysRefreshDict: "/system/refresh/refreshDict",//
    sysRefreshRoleMenu: "/system/refresh/refreshRoleMenu",//
    sysRefreshRoleResources: "/system/refresh/refreshRoleResources",//
    sysRefreshRoleMenuResource: "/system/refresh/refreshRoleMenuResource",//

    refreshDict: "/system/dict/manage/dictList",//字典信息
    sysUserLogin: "/system/user/login",//用户登录
    refreshToken: "/system/user/public/refreshToken",//刷新登录信息
    checkToken: "/system/user/public/checkToken",

};

// * 刷新字典
export async function getDict(nowPath: any = '/login'): Promise<any> {
    return $http.post(API.refreshDict, {})
        .then((res: any) => {
            if (res.success) {
                //2020-01-01
                setStorage("nowDate", res.data.nowDate);
                //01:01:01
                setStorage("nowTime", res.data.nowTime);
                //2020-01-01 01:01:01
                setStorage("nowDateTIme", res.data.nowDateTIme);


                //读取本地版本号
                let oldAdminVersion = getAdminVersion();
                //更新版本号
                setAdminVersion(res.data.adminVersion);
                setServerVersion(res.data.serverVersion);
                setAdminShowLog(res.data.adminShowLog);

                // 不是登录页就检查
                if (nowPath.indexOf("/login") == -1) {
                    // 检查版本号
                    if (oldAdminVersion != res.data.adminVersion && oldAdminVersion != "0") {
                        window.location.reload();
                        return;
                    }
                }
            }
            return res;
        })
}
